﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.IO;
using System.Xml;

using System.Data;
using Gift.WebApp;
using System.Collections;

using Gift.DAL;
using Gift.Model;

public partial class cn_shopping_cart : BasePage
{

 

    // Methods
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected StringBuilder ShoppingCartBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            string user = "";
            if ((base.LoginUserMember == null) && (HttpContext.Current.Request.Cookies["shopping_cart_mac"] != null))
            {
                user = HttpContext.Current.Request.Cookies["shopping_cart_mac"].Value;
            }
            else if (base.LoginUserMember!= null)
            {
                user = base.LoginUserMember.MemberId;
            }
            DataTable shoppingCartByUser = BaseFactory.theShoppingCart.GetShoppingCartByUser(user);
            if (shoppingCartByUser.Rows.Count > 0)
            {
                   foreach (DataRow row in shoppingCartByUser.Rows)
                {
                    builder.AppendLine("<tr>");
                    builder.AppendLine(string.Concat(new object[] { "<td><a href=\"/cn/goods.html?id=", row["gId"], "\" target=\"_blank\">", row["goodsArtno"], "</a></td>" }));
                    DataTable goodGalleryByGoods = BaseFactory.theGoodGallery.GetGoodGalleryByGoods(Convert.ToInt32(row["gid"]));
                    builder.AppendLine(string.Concat(new object[] { "<td><a href=\"/cn/goods.html?id=", row["gId"], "\" target=\"_blank\"><img src=\"", goodGalleryByGoods.Rows[0]["thumbImg"], "\" alt=\"", goodGalleryByGoods.Rows[0]["imgAlt"], "\" /></a></td>" }));
                    builder.AppendLine(string.Concat(new object[] { "<td><a href=\"/cn/goods.html?id=", row["gId"], "\" target=\"_blank\">", row["goodsName"], "</a>" }));
                    DataTable table3 = BaseFactory.theGoodsEntitysSpecifications.FrontDeskGetGoodsEntitysSpecificationsByGoodsEntitys(Convert.ToInt32(row["geid"]));
                    for (int i = 0; i < table3.Rows.Count; i++)
                    {
                        builder.Append(string.Concat(new object[] { (i > 0) ? "&nbsp;&nbsp;" : "", table3.Rows[i]["specificationsName"], "：", table3.Rows[i]["specificationsValueName"] }));
                    }
                    builder.Append("</td>");
                    builder.AppendLine("<td>" + string.Format("{0:C}", Convert.ToDecimal(row["salePrice"])) + "</td>");
                    builder.AppendLine(string.Concat(new object[] { "<td><p class=\"number\"><input type=\"button\" value=\"-\" onclick=\"amountJian('", row["sid"], "');\" /><span><input id=\"amount", row["sid"], "\" type=\"text\" maxlength=\"5\" onchange=\"changeAmount('", row["sid"], "');\" value=\"", row["amount"], "\"  /></span><input type=\"button\" value=\"+\" onclick=\"amountJia('", row["sid"], "');\" /></p></td>" }));
                    builder.AppendLine("<td>" + string.Format("{0:C}", Convert.ToDecimal(row["total"])) + "</td>");
                    builder.AppendLine("<td><a href=\"javascript:\" onclick=\"customButton('确定要清空购物车吗？','确定','shoppingCartHandler.ashx?sid=" + row["sid"] + "','取消');\">删除</a></td>");
                    builder.AppendLine("</tr>");
                }
                return builder;
            }
            builder.AppendLine("<tr>");
            builder.AppendLine("<td colspan=\"7\" style=\"text-align: center; color: #ff0000;\">购物车目前没有加入任何商品</td>");
            builder.AppendLine("</tr>");
        }
        catch
        {
        }
        return builder;
    }

    protected StringBuilder ShoppingCartTotalBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            int num = 0;
            int num2 = 0;
            decimal num3 = 0M;
            DataTable shoppingCartByUser = new DataTable();
            string user = "";
            if ((base.LoginUserMember == null) && (HttpContext.Current.Request.Cookies["shopping_cart_mac"] != null))
            {
                user = HttpContext.Current.Request.Cookies["shopping_cart_mac"].Value;
            }
            else if (base.LoginUserMember != null)
            {
                user = base.LoginUserMember.MemberId;
            }
            shoppingCartByUser = BaseFactory.theShoppingCart.GetShoppingCartByUser(user);
            foreach (DataRow row in shoppingCartByUser.Rows)
            {
                num += Convert.ToInt32(row["giveIntegral"]) * Convert.ToInt32(row["amount"]);
                num2 += Convert.ToInt32(row["amount"]);
                num3 += Convert.ToDecimal(row["total"]);
            }
            builder.AppendLine(string.Concat(new object[] { "<p id=\"pTotal\"><span>商品数量总计：<strong>", num2, "</strong>件</span><span>赠送积分总计：<strong>", num, "</strong>分</span><span>商品金额总数：<strong>", string.Format("{0:C}", num3), "</strong></span></p>" }));
        }
        catch
        {
        }
        return builder;
    }

}